package com.jhj.utils;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

import com.qiniu.util.Auth;
import com.qiniu.util.StringMap;

public class QiNiuFileUtil {

	/**
	 * 七牛云ak
	 */
	public static final String QINIU_AK = "C9UzQYkfqzmto5AnoJ-JmIo-exzk-Qae2kZoq0vs";
	
	public static final String QINIU_SK = "7EQpNMhVpQkiXKnigoXUEMxJVvi_5I1S8N_5IBw0";	
	
	public static final String BUCKET_NAME = "resume-video";
	
	/**
	 * 获取上传token
	 * @return
	 */
	public static String getUpToken() {
		
		
		Auth auth = Auth.create(QINIU_AK, QINIU_SK);
		StringMap putPolicy = new StringMap();
//		putPolicy.put("callbackUrl", "http://api.example.com/qiniu/upload/callback");
		putPolicy.put("callbackBody", "{\"key\":\"$(key)\",\"hash\":\"$(etag)\",\"bucket\":\"$(bucket)\",\"fsize\":$(fsize)}");
		putPolicy.put("callbackBodyType", "application/json");
		long expireSeconds = 3600;
		String upToken = auth.uploadToken(BUCKET_NAME, null, expireSeconds, putPolicy);
		
		return upToken;
	}	
	
	

	public static void main(String[] args) throws Exception {
		System.out.println(QiNiuFileUtil.getUpToken());
	}
}